from django.shortcuts import render
from xpu import models
import datetime
import sqlite3
from django.shortcuts import HttpResponse
# Create your views here.
def index(request):
    if request.method == "POST":
        info={}
        name = request.POST.get('name')  # 学号
        xueyuan = request.POST.get('xueyuan')  # 密码
        kahao = request.POST.get('kahao')  # 学号
        phone = request.POST.get('phone')  # 密码
        email = request.POST.get('email')  # 学号
        people = request.POST.get('people')  # 密码
        local = request.POST.get('local')  # 学号
        time = request.POST.get('time')  # 密码
        data = request.POST.get('data')  # 学号
        use = request.POST.get('use')  # 密码
        shenfen = request.POST.get('shenfen')  # 密码
        info["name"] = name
        info["xueyuan"] = xueyuan
        info["kahao"] = kahao
        info["shenfen"] = shenfen
        info["phone"] = phone
        info["email"] = email
        info["people"] = people
        info["local"] = local
        info["time"] = time
        info["data"] = data
        info["use"] = use
        models.SubmitInfo.objects.create(name=name,xueyuan=xueyuan,shenfen=shenfen,kahao=kahao,phone=phone, email=email,people=people,local=local,time=time,date=data,use=use,satu="待审核")
        return render(request, "success.html")
    today = datetime.date.today()
    print(today)
    week={
        "data1":(today+datetime.timedelta(days=1)).strftime("%Y-%m-%d")  ,
          "data2":(today+datetime.timedelta(days=2)).strftime("%Y-%m-%d")  ,
          "data3":(today+datetime.timedelta(days=3)).strftime("%Y-%m-%d")  ,
          "data4":(today + datetime.timedelta(days=4)).strftime("%Y-%m-%d"),
          "data5":(today + datetime.timedelta(days=5)).strftime("%Y-%m-%d"),
          "data6":(today + datetime.timedelta(days=6)).strftime("%Y-%m-%d"),
          "data7":(today + datetime.timedelta(days=7)).strftime("%Y-%m-%d"),
          }
    response = render(request,"index.html",week)
    return response


def qiandao(request):
    if request.method == "POST":
        email = request.POST.get('email') # 学号
        # print(email)
        obj=models.SubmitInfo.objects.filter(email=email,date=datetime.date.today(),satu="通过未签到")
        print(obj)

        if obj:
            obj.update(satu='已签到')
            return render(request, "qdsuccess.html")
        else:
            print("ll")
            return render(request, "qdfail.html")
    return render(request,"qiandao.html")